<template>
	<view>
		<!-- 顶部导航 -->
		<u-navbar :background="background">
			<view class="ft_16 fw-b">
				优惠券
			</view>
		</u-navbar>
		<view class="content">
			<u-tabs-swiper ref="uTabs" :list="list" :is-scroll="false" bar-height="6" bar-width="250" active-color="#e67920" :current="current" @change="tabsChange" height="90"></u-tabs-swiper>
			<swiper :current="swiperCurrent" @transition="transition" @animationfinish="animationfinish" :style="{height:scrollHeight + 'px'}">
				<!-- 待使用 -->
				<swiper-item class="swiper-item">
					<scroll-view scroll-y style="height: 100%;width: 100%;" @scrolltolower="onreachBottom">
						<view class="con_2">
							<view class="con_2_1 display just_space" v-for="(item,index) in couponList" :key="index">
								<view class="display">
									<view class="quota">
										<view class="ft_14 fw-b c-yellow">
											<text>￥</text>
											<text class="ft_24">{{item.coupon_price}}</text>
										</view>
										<view class="ft_12">
											{{item.limit==0?'无限制':'满'+item.price_cond+'可用'}}
										</view>
									</view>
									<view class="" style="line-height: 1.8em;">
										<view class=" ft_16 fw-b">
											{{item.coupon_title}}
										</view>
										<view class=" ft_10 c-999">
											{{item.use_time}}
										</view>
										<view class="ft_12 c-333">
											{{item.category_name}}
										</view>
									</view>
								</view>
								<view class="ft_12 useOf" @click="useof(item)">
									立即使用
								</view>
							</view>
						</view>
					</scroll-view>
				</swiper-item>
				<!-- 已使用 -->
				<swiper-item class="swiper-item">
					<scroll-view scroll-y style="height: 100%;width: 100%;" @scrolltolower="onreachBottom">
						<view class="con_2">
							<view class="con_2_1 display just_space" v-for="(item,index) in couponList1" :key="index">
								<view class="display">
									<view class="quota">
										<view class="ft_14 fw-b c-999">
											<text>￥</text>
											<text class="ft_24">{{item.coupon_price}}</text>
										</view>
										<view class="ft_12">
											{{item.limit==1?'无限制':'满'+item.price_cond+'可用'}}
										</view>
									</view>
									<view class="" style="line-height: 1.8em;">
										<view class=" ft_16 fw-b">
											{{item.coupon_title}}
										</view>
										<view class=" ft_10 c-999">
											{{item.use_time}}
										</view>
										<view class="ft_12 c-333">
											{{item.category_name}}
										</view>
									</view>
								</view>
								<view class="ft_12 useOf1">
									已使用
								</view>
							</view>
						</view>
					</scroll-view>
				</swiper-item>
				<!-- 已过期 -->
				<swiper-item class="swiper-item">
					<scroll-view scroll-y style="height: 100%;width: 100%;" @scrolltolower="onreachBottom">
						<view class="con_2">
							<view class="con_2_1 display just_space" v-for="(item,index) in couponList2" :key="index">
								<view class="display">
									<view class="quota">
										<view class="ft_14 fw-b c-999">
											<text>￥</text>
											<text class="ft_24">{{item.coupon_price}}</text>
										</view>
										<view class="ft_12">
											{{item.limit==1?'无限制':'满'+item.price_cond+'可用'}}
										</view>
									</view>
									<view class="" style="line-height: 1.8em;">
										<view class=" ft_16 fw-b">
											{{item.coupon_title}}
										</view>
										<view class=" ft_10 c-999">
											{{item.use_time}}
										</view>
										<view class="ft_12 c-333">
											{{item.category_name}}
										</view>
									</view>
								</view>
								<view class="ft_12 useOf1">
									已过期
								</view>
							</view>
						</view>
					</scroll-view>
				</swiper-item>
				
			</swiper>
			

		</view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				background:{backgroundColor: '#ffffff',}, //导航栏背景
				list:[
					{
					name: '待使用'
					}, {
					name: '已使用'
					}, {
					name: '已过期',
					},
				],
				current: 0, // tabs组件的current值，表示当前活动的tab选项
				swiperCurrent: 0, // swiper组件的current值，表示当前那个swiper-item是活动的
				scrollHeight:"", //滚动高度
				
				couponList:[], //未使用
				couponList1:[], //已使用
				couponList2:[], //已过期
				
			}
		},
		onLoad() {
			this.getheight() //获取滚动高度
			this.getyhqList() //获取优惠券
		},
		methods: {
			getyhqList(){ //获取优惠券
				let type=['1','2','3']
				type.forEach(i=>{
					this.$myRequest('user/couponList',{
						type:i
					}).then(res=>{
						if(res.data.code==1){
							if(i==1){ //未使用
								console.log(res.data.data);
								this.couponList=res.data.data.coupon
							}else if(i==2){ //已使用
								console.log(res.data.data);
								this.couponList1=res.data.data.coupon
							}else{ //已过期
								console.log(res.data.data);
								this.couponList2=res.data.data.coupon
							}
						}
					})
				})
				
			},
			useof(item){ //使用优惠券
				console.log(item);
				uni.switchTab({
					url:"../../../../pages/index/index"
				})
			},
			
			getheight(){ //获取滚动高度
				let windowHeight=uni.getStorageSync('windowHeight')
				let statusBarHeight=uni.getStorageSync('statusBarHeight')
				this.scrollHeight=windowHeight - statusBarHeight - 44
			},
			
			// tabs通知swiper切换
			tabsChange(index) {
				this.swiperCurrent = index;
			},
			// swiper-item左右移动，通知tabs的滑块跟随移动
			transition(e) {
				let dx = e.detail.dx;
				// this.$refs.uTabs.setDx(dx);
			},
			// 由于swiper的内部机制问题，快速切换swiper不会触发dx的连续变化，需要在结束时重置状态
			// swiper滑动结束，分别设置tabs和swiper的状态
			animationfinish(e) {
				let current = e.detail.current;
				this.$refs.uTabs.setFinishCurrent(current);
				this.swiperCurrent = current;
				this.current = current;
			},
			// scroll-view到底部加载更多
			onreachBottom() {
				
			}
			
		}
	}
</script>

<style lang="scss">
page{
	background-color: #fafafa;
}
.content{
	.con_1{
		
	}
	.con_2{
		padding: 10px;
		.con_2_1{
			padding: 15px;
			background-color: #FFFFFF;
			border-radius: 5px;
			margin-bottom: 10px;
			.quota{
				width: 80px;text-align: center;margin-right: 10px;
			}
			.useOf{
				padding: 5px 10px;background: linear-gradient(90deg, #F1A421 0%, #E4741F 100%);color: #FFFFFF;border-radius: 30px;
			}
			.useOf1{
				background-color: #dddddd;
				padding: 5px 10px;color: #FFFFFF;border-radius: 30px;
			}
		}
	}
}

</style>
